﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
    SqlConnection SqlCn;
	public DAL()
	{
		//
		// TODO: Add constructor logic here
		//
        SqlConnectionStringBuilder cnBuild = new SqlConnectionStringBuilder();
        cnBuild.DataSource = "(local)\\NBE_posserver";
        cnBuild.InitialCatalog = "AhliBank_inventory";
        cnBuild.UserID = "sa";
        cnBuild.Password = "P@$$w0rD";
        SqlCn = new SqlConnection(cnBuild.ConnectionString);

        try
        {
            SqlCn.Open();
        }

        catch
        {}
	}

    public DataSet GetAllMerchants(string sortExp)
    {
        string cmd1 = "select * from MachineLog";        
        DataSet ds = new DataSet();
        SqlDataAdapter dA = new SqlDataAdapter(cmd1, SqlCn);
        dA.Fill(ds,"Log");
        ds.Tables["Log"].DefaultView.Sort=sortExp;
        return ds; 
    }

    public DataTable BoundMerchants(string sortExp)
    {
        DataTable dt=new DataTable();
        string cmd1 = "select POS_Mach_SN, pos_Mach_location as Loc from POS_Machine";
        SqlCommand sqlCmd = new SqlCommand(cmd1,SqlCn);
        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        da.Fill(dt);
        dt.DefaultView.Sort = sortExp;
        return dt;
    }
}